#include "../menu.h"
#include "../aw_gui_app.h"
#include "logo_dat.h"
#include "sys/time.h"
#include "filenav.h"
#include "ctrlconvert.h"
#include "LogoEvent.h"

static INT8U loading_time=0;
static INT8U Max_Loading_Time=1;

INT32U *writeadd;
INT8U soft_version_time=0;
extern AWMSG *AutoRunMsg;
extern char CurDriver[10];
extern INT8U GetAutoRunPara();
extern void AWCreateAllWindow();

extern void ReloadLogo();
extern int check_media_file_exist(char* path_name ,unsigned media_type,int search_way);

#ifdef RESUME_PLAY
extern void send_gplayer_file(char *file_name);
extern RESUME_FILEINFO resume_file;
extern INT8U ResumePlayFlag;
extern INT8U ResumeFunction;
#endif

INT32S LoadingWinOnShow(PHWND hwnd, INT32S lpParam)
{
    Max_Loading_Time=6;
    loading_time = 0 ;
	soft_version_time=2;
	return 0 ;
}

INT32S LoadingWinOnHide(PHWND hwnd, INT32S lpParam)
{
    return 0 ;
}

INT32S LoadingOnPaint(PHWND hwnd, INT32S lpParam)
{
    return 0 ;
}
extern char loading_autorun_flag;
void AutoRunInit(void)
{
#ifdef RESUME_PLAY
    INT32U file_type = 0;
    
    ResumeFunction = 1;
    ResumePlayFlag = GetResumePlayFlagPara();
    if(ResumePlayFlag == 1)
    {
        GetResumeFilePara(resume_file.file_name);
	    resume_file.time = GetResumeTimePara();
	    if(resume_file.time == 0xffffffff)
		    resume_file.time = 0;
		
		INT8U FileExist = 0;
		INT16U DriverNum = 0;
        DriverNum = GetDriverNum();
		
        if(DriverNum > 0)
        {
            if(FileNavFileExists(resume_file.file_name))
                FileExist = 1;
            else
            {
    	        resume_file.file_name[5] = 'C'; 
        		for(INT8U i=0; i<DriverNum; i++)
        		{
        		    if(FileNavFileExists(resume_file.file_name))
        		    {
                        FileExist = 1;
                        break;
                    }
        		    resume_file.file_name[5]++;
        		}
    		}
        }
        if(FileExist)
        {
        #if RESUME_INTERVAL_TIME
            //SetResumePlayFlagPara(1);
        #else
            SetResumePlayFlagPara(0);
        #endif
            file_type = GetMediaType(resume_file.file_name);
        #ifdef TIME_SEARCH
            extern VIDEO_INFO video_inf;
            extern INT8U TimeSearchFlag;
			TimeSearchFlag = 1;
			GetVideoInfo(resume_file.file_name,&video_inf);
        #endif

    		if ((file_type == MEDIA_MPEG2) || (file_type == MEDIA_MPEG1)) 
    		{
                PreviewVobPlayer(resume_file.file_name);
                return ;
    		}
    		else if (file_type == MEDIA_AVI)
    		{    
                PreviewAviPlayer(resume_file.file_name);
                return ;
    		}
    		else if (file_type == MEDIA_MOV) 
    		{
                PreviewGPlayer(resume_file.file_name);
                return ;
    		}
        #ifdef SUPPORT_RM
    		else if (file_type == MEDIA_REAL) 
    		{
                PreviewRmPlayer(resume_file.file_name);
                return ;
    		}
        #endif
        }
        else
        {
            resume_file.time = 0;
        }
    }
    else
    {
        resume_file.time = 0;
    }
    ResumePlayFlag = 0;
#endif

	int i;
//	AWCreateAllWindow();
#if 1	
	for(i=0;i<MAX_MOUNT_POINT_NUM;i++)
	{
		if((check_media_file_exist(CurDriver,(MEDIA_PIC | AW_VIDEO_LIST | AW_AUDIO_LIST),0x300|0x1)))
		{
			
			auto_run_function(CurDriver);
			   
			return;
		}
		CurDriver[5]++;
	}
	CurDriver[5]='C';
#endif
	ReloadLogo();
	
	GUIShowWindow(WinDeviceSelect);  


}

INT32S LoadingOnOtherEvent(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    static INT8U sametime=0;
    switch(msg_type)
    {
        case WM_SECOND_TIMEOUT:
            if(loading_time > Max_Loading_Time)
            { 
                GUIHideWindow(LoadingWin);
                AWCreateAllWindow();
                if(!GetAutoRunPara())
                {
                    AutoRunInit();
    	        }
    	        else
                {
                #ifdef RESUME_PLAY
                    ResumeFunction = 0;
                #endif
                    ReloadLogo();
                    GUIShowWindow(WinDeviceSelect);
                }
                loading_autorun_flag = 0;	
                break ;
            }
    	   
            loading_time++ ;
            break;
    	}
    return 0 ;
}

